<?php
function getIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))
    {
       $ipAddr=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    {
       $ipAddr=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
       $ipAddr=$_SERVER['REMOTE_ADDR'];
    }
   return $ipAddr;
 }

echo getIpAddr();

?>
